#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#define endl '\n'
#define int long long
#define pii pair<int, int>
using namespace std;

// 已知
int n, m, x;
vector<int> g[300005];
// 未知
int change[300005];
int cnt[300005];
void input()
{
    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
    {
        cin >> x;
        for (int j = 1, t; j <= x; ++j)
        {
            cin >> t;
            g[i].push_back(t);
        }
    }
    for (int i = 0; i < n; ++i)
    {
        cin >> x;
        change[x] = i; // 第x个食材，在第i天改变
    }
}
void solve()
{
    for (int i = 1; i <= m; ++i)
    {
        int mx = 0; // 第i个菜品，最晚在mx天解锁
        for (auto c : g[i]) mx = max(mx, change[c]);
        cnt[mx]++; // mx天解锁的菜品数量+1
    }
}

void output()
{
    int sum = 0;
    for (int i = 0; i < n; ++i)
    {
        sum += cnt[i]; // 累计第i天解锁的菜品数量
        cout << sum << endl;
    }
}

signed main()
{
    input();
    solve();
    output();
    return 0;
}